<template>
  <div class="equipmentCalibration">
    <div class="equipmentCalibration_treeBg">
      <MetaTreeList title-size="20" title="设备" :icon="treeIcon" :default-props="defaultProps" :tree-data="equTreeData" @treeItemChoose="roloeItemChoose"></MetaTreeList>
    </div>
    <div class="equipmentCalibration_infoBg">
      <div v-if="Object.keys(roleInfoItem).length > 0" class="equipmentCalibration_info">
        <div class="equipmentC_infoTitleBg">
          <div class="equipmentC_infoTitle">设备信息</div>
          <div class="equipmentC_infoContent">
            <div class="equipmentC_infoItemBg">
              <img src="@/assets/images/v4/eInfo_showName.png" class="equipmentC_infoItemIconShowName">
              <div class="equipmentC_infoItemText">用户设备名称&nbsp;&nbsp;{{ roleInfoItem.customizeName && roleInfoItem.customizeName !== '' ? roleInfoItem.customizeName : roleInfoItem.equipmentname }}</div>
            </div>
            <div class="equipmentC_infoItemBg">
              <img src="@/assets/images/v4/eInfo_showName.png" class="equipmentC_infoItemIconName">
              <div class="equipmentC_infoItemText">设备名称&nbsp;&nbsp;{{ roleInfoItem.alias }}</div>
            </div>
            <div class="equipmentC_infoItemBg">
              <img src="@/assets/images/v4/eInfo_snid.png" class="equipmentC_infoItemIconSnid">
              <div class="equipmentC_infoItemText">设备版本&nbsp;&nbsp;v{{ roleInfoItem.version }} ({{ roleInfoItem.snid }})</div>
            </div>
            <div class="equipmentC_infoItemBg">
              <!-- 1在线2调试3维修4报警 -->
              <img src="@/assets/images/v4/eInfo_equipmentStatus.png" class="equipmentC_infoItemIconSnid">
              <div v-if="equipmentOnType == '2'" class="equipmentC_infoItemText">设备状态&nbsp;&nbsp;调试</div>
              <div v-else-if="equipmentOnType == '3'" class="equipmentC_infoItemText">设备状态&nbsp;&nbsp;维修
                <span v-if="parseFloat(roleInfoItem.version) >= 3 && equipmentStatusNow == '20' && xmStatus == '10'">（休眠唤醒中）</span>
                <span v-else-if="parseFloat(roleInfoItem.version) >= 3 && equipmentStatusNow == '20' && xmStatus == '20'">（休眠充电中）</span>
              </div>
              <div v-else-if="equipmentOnType == '4'" class="equipmentC_infoItemText">设备状态&nbsp;&nbsp;报警
                <span v-if="parseFloat(roleInfoItem.version) >= 3 && equipmentStatusNow == '20' && xmStatus == '10'">（休眠唤醒中）</span>
                <span v-else-if="parseFloat(roleInfoItem.version) >= 3 && equipmentStatusNow == '20' && xmStatus == '20'">（休眠充电中）</span>
              </div>
              <div v-else class="equipmentC_infoItemText">设备状态&nbsp;&nbsp;在线 
                <span v-if="parseFloat(roleInfoItem.version) >= 3 && equipmentStatusNow == '20' && xmStatus == '10'">（休眠唤醒中）</span>
                <span v-else-if="parseFloat(roleInfoItem.version) >= 3 && equipmentStatusNow == '20' && xmStatus == '20'">（休眠充电中）</span>
              </div>
            </div>
            <div class="equipmentC_infoItemBg">
              <img src="@/assets/images/v4/eInfo_elecMain.png" class="equipmentC_infoItemIconSnid">
              <div class="equipmentC_infoItemText">电源电压&nbsp;&nbsp;{{ equipmentVoltage !== '' ? equipmentVoltage : '-' }} / {{electricityBackup !==''?electricityBackup : '-'}} V
              </div>
            </div>
            <div class="equipmentC_infoItemBg">
              <img src="@/assets/images/v4/eInfo_collStatus.png" class="equipmentC_infoItemIconSnid">
              <!-- 1连续采集关，2连续采集开，3样品采集，4暗电流，5标准板，6定时关，7定时开 -->
              <div v-if="collectionType == '2'" class="equipmentC_infoItemText">采集状态&nbsp;&nbsp;连续采集</div>
              <div v-else-if="collectionType == '3'" class="equipmentC_infoItemText">采集状态&nbsp;&nbsp;样品采集</div>
              <div v-else-if="collectionType == '4'" class="equipmentC_infoItemText">采集状态&nbsp;&nbsp;暗电流定标</div>
              <div v-else-if="collectionType == '5'" class="equipmentC_infoItemText">采集状态&nbsp;&nbsp;标准板定标</div>
              <div v-else-if="collectionType == '7'" class="equipmentC_infoItemText">采集状态&nbsp;&nbsp;定时采集</div>
              <div v-else class="equipmentC_infoItemText">采集状态&nbsp;&nbsp;待机</div>
            </div>
            <!-- <div class="equipmentC_infoItemBg">
              <img src="@/assets/images/v4/eInfo_collStatus.png" class="equipmentC_infoItemIconSnid">
              <div  class="equipmentC_infoItemText">备用电池电压&nbsp;&nbsp;2.5V</div>
            </div> -->

            <div v-if="collectionType == '7' && workModel == '03'" class="equipmentC_infoItemBg">
              <img src="@/assets/images/v4/eInfo_nowCollStatus.png" class="equipmentC_infoItemIconSnid">
              <div v-if="realWorkModel == '10'" class="equipmentC_infoItemText">当前采集模式&nbsp;&nbsp;半休眠模式</div>
              <div v-else-if="realWorkModel == '20'" class="equipmentC_infoItemText">当前采集模式&nbsp;&nbsp;全休眠模式（采集）</div>
              <div v-else-if="realWorkModel == '30'" class="equipmentC_infoItemText">当前采集模式&nbsp;&nbsp;全休眠模式（待机）</div>
              <div v-else class="equipmentC_infoItemText">当前采集模式&nbsp;&nbsp;-</div>
            </div>

          </div>
        </div>
        <div class="equipmentC_optionArea">
          <div class="equipmentC_optionTitle">设备操作系统</div>
          <div class="equipmentC_optionBg">
            <div class="equipmentC_left">
              <img v-if="lightSource == '1'" class="equipmentCLeft_water" src="@/assets/images/v4/water_o.png">
              <img v-else class="equipmentCLeft_water" src="@/assets/images/v4/water.png">
              <img v-if="equipmentStatusNow == '10'" src="@/assets/images/v4/equipment_o.png" class="equipmentCLeft_equipment_o">
              <img v-else src="@/assets/images/v4/equipment.png" class="equipmentCLeft_equipment">
              <div class="equipmentCLeft_btnArea">
                <div class="equipmentCLeft_btn">
                  <div class="equipmentCLeft_btnItem" @click="doParamsOption('params')">参数配置</div>
                  <div class="equipmentCLeft_btnItem" @click="openDialog('adl')">暗电流定标</div>
                </div>
                <div class="equipmentCLeft_btn">
                  <div class="equipmentCLeft_btnItem" @click="openDialog('dc')">样品采集</div>
                  <div class="equipmentCLeft_btnItem" @click="openDialog('bzb')">标准板定标</div>
                </div>
              </div>
            </div> 
            <div class="equipmentC_right">
              <div class="equipmentC_btnGroup">
                <el-button v-if="collectionType == '7'" class="equipmentC_btn" @click="stopDsOption" round type="danger" plain>停止采集</el-button>
                <el-button v-else-if="collectionType == '2' || collectionType == '3' || collectionType == '4' || collectionType == '5'" class="equipmentC_btn" @click="stopDcOption" round type="danger" plain>停止采集</el-button>
                <el-button v-if="equipmentStatusNow == '20' && parseFloat(roleInfoItem.version) >= 3.2" class="equipmentC_btn" round @click="closeEquipment" type="danger" plain>关机</el-button>
                <el-button v-if="equipmentStatusNow == '20' && parseFloat(roleInfoItem.version) >= 3" class="equipmentC_btn" round @click="doOpenLock" type="warning" plain>开启电磁锁</el-button>
                <el-button class="equipmentC_btn" round @click="openCalibrationInfo()">定标详情</el-button>
              </div>
              <div class="equipmentC_settingArea">
                <div class="equipmentC_settingContent">
                  <div class="equipmentC_settingItem">
                    <div class="equipmentC_settingTitle">电压阈值</div>
                    <el-input-number size="small" v-model="voltageDown" :min="0" :max="13" class="equipmentC_settingNumberInput" @change="voltageDownChange"></el-input-number>&nbsp;V
                    <img src="@/assets/images/v4/arrow.png"> 
                    <el-input-number size="small" v-model="voltageUp" :min="voltageDown" :max="13" class="equipmentC_settingNumberInput"></el-input-number>&nbsp;V
                  </div>
                  <div class="equipmentC_settingItem">
                    <div class="equipmentC_settingTitle">暗电流参与计算</div>
                    <el-switch v-model="darkCurrentInCalculation" 
                      active-value="1"
                      inactive-value="0">
                    </el-switch>
                  </div>
                  <div class="equipmentC_settingItem">
                    <div class="equipmentC_settingTitle">定标系数</div>
                    <el-select v-model="dbxsType" placeholder="请选择定标系数" size="small" class="equipmentC_settingSelect">
                      <el-option label="白板系数" value="0"></el-option>
                      <el-option label="灰板系数" value="1"></el-option>
                      <el-option label="无系数" value="2"></el-option>
                    </el-select>  
                  </div>
                </div>
                <div class="equipmentC_saveBtn">
                  <div class="equipmentC_save" @click="saveCalibrationParams()">保存</div>
                </div>
              </div>
              <div class="equipmentC_paramArea">
                <div class="equipmentC_paramTitle">设备参数
                  <i class="el-icon-refresh equipmentCParams_refreshIcon" @click="equipmentParamsRefresh"></i>
                </div>
                <div class="equipmentC_paramItem">
                  <div class="equipmentC_paramName">可见光积分</div>
                  <el-input-number size="medium" class="equipmentC_paramInput" :min="0" :max="255" v-model="equipmentParams.visible_light_integral"></el-input-number>
                </div>
                <div class="equipmentC_paramItem">
                  <div class="equipmentC_paramName">增益</div>
                  <el-input-number size="medium" class="equipmentC_paramInput" :min="0" :max="6" v-model="equipmentParams.data_value_gain"></el-input-number>
                </div>
                <div class="equipmentC_paramItem">
                  <div class="equipmentC_paramName">偏压</div>
                  <el-input-number size="medium" class="equipmentC_paramInput" :min="0" v-model="equipmentParams.power_supply_bias"></el-input-number>
                </div>
                <div class="equipmentC_paramItem">
                  <div class="equipmentC_paramName">短波积分</div>
                  <el-input-number size="medium" class="equipmentC_paramInput" :min="0" v-model="equipmentParams.shot_wave_integral"></el-input-number>
                </div>
                <div class="equipmentC_paramItem">
                  <div class="equipmentC_paramName">补光灯电压</div>
                  <el-input-number size="medium" class="equipmentC_paramInput" :min="1" :max="5" v-model="equipmentParams.fill_lamp_voltage"></el-input-number>
                </div>
              </div>
            </div> 
          </div>
        </div>
        <div class="equipmentC_echartsArea">
          <div class="equipmentC_echartsDndataBg">
            <div ref="dnChart" class="equipmentC_echartsDndata"></div>
          </div> 
          <div class="equipmentC_echartsReflectivityBg">
            <div ref="reflectivityChart" class="equipmentC_echartsReflectivity"></div>
          </div>
        </div>
      </div>
    </div>
    <el-dialog
      v-if="equipmentOptionDialog"
      title="设备控制"
      :visible.sync="equipmentOptionDialog"
      width="40%"
      modal
      center
      :close-on-click-modal="false"
      :close-on-press-escape="false">
      <el-form ref="equipmentOption_form" :model="equipmentOption" label-width="130px" :rules="equipmentOptionRules">
        <el-form-item label="采集次数" prop="cjTimes">
          <el-input-number v-model="equipmentOption.cjTimes" placeholder="请输入采集次数" :min="1" :max="300" :precision="0"></el-input-number>
        </el-form-item>
        <el-form-item label="备注">
          <el-input v-model="equipmentOption.remark" placeholder="请输入备注"></el-input>
        </el-form-item>
      </el-form>
      <div class="dialogFooter">
        <el-button size="mini" @click="editDialogClose()">取消</el-button>
        <el-button
          type="primary"
          size="mini"
          @click="editDialogSubmit()"
        >采集</el-button>
      </div>
    </el-dialog>
    <el-dialog
      v-if="calibrationInfoDialog"
      title="定标详情"
      :visible.sync="calibrationInfoDialog"
      width="80%"
      modal
      center
      :close-on-click-modal="false"
      :close-on-press-escape="false">
      <MetaPageTable
        ref="calibrationInfoTable"
        class="calibrationInfo_table"
        :table-title="'[' + roleInfoItem.alias + '] 定标记录'"
        tableHeight="400"
        :need-checkbox="false"
        :is-auto-req="false"
        :display-item="displayItem"
        :table-data="calibrationTableData"  
        :btn-group="ecDetailBtnGroup"
        @btnClick="tableBtnClick"
        :line-btn-group="lineBtnGroup"
        @lineBtnClick="tableInlineBtnClick"
      />
    </el-dialog>
    <el-dialog
      v-if="echartDialog"
      title="查看定标曲线"
      :visible.sync="echartDialog"
      width="80%"
      center
      modal
      :close-on-click-modal="false"
      :close-on-press-escape="false"
    >
      <div class="echartForCalibrationBg" 
        v-loading="echartLoading"
        element-loading-text="拼命加载中"
        element-loading-spinner="el-icon-loading">
        <div class="echartForCalibration_bzb">
          <div class="echartForCalibration_bzbItem">
            <div id="echartForCalibration_bzbOriginal" class="echartForCalibrationItem_bzb"></div>
          </div>
          <div class="echartForCalibration_bzbItem">
            <div id="echartForCalibration_bzbHandle" class="echartForCalibrationItem_bzb"></div>
          </div>
        </div>
        <div class="echartForCalibration_adl">
          <div class="echartForCalibration_adlItem">
            <div id="echartForCalibration_adlOriginal" class="echartForCalibrationItem_adl"></div>
          </div>
          <div class="echartForCalibration_adlItem">
            <div id="echartForCalibration_adlHandle" class="echartForCalibrationItem_adl"></div>
          </div>
        </div>
      </div>
    </el-dialog>
    <el-dialog
      v-if="dbDataImportFlag"
      title="文件上传"
      :visible.sync="dbDataImportFlag"
      width="40%"
      modal
      center
      :close-on-click-modal="false"
      :close-on-press-escape="false"
    >
      <el-form label-width="80px" style="display: inline-block; width: 100%">
        <el-form-item label="选择文件" class="dataManagement_importFormItem">
          <el-upload
            style="float: left"
            :action="dbDataImportUrl"
            :file-list="dbDataFileList"
            :on-success="uploadSuccess"
            :before-upload="beforeUpload"
            :headers="{
              'x-auth-token': token,
            }"
            :data="{
              equipmentId: roleInfoItem.id,
            }"
            :limit="1"
          >
            <el-button size="small" type="primary">点击上传</el-button>
            <div slot="tip" class="el-upload__tip">请上传txt文件</div>
          </el-upload>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
import MetaPageTable from "../components/MetaPageTable";
import MetaTreeList from '../components/MetaTreeList'
import MetaNumberInput from '../components/MetaNumberInput'
import deepClone from '../utils/deepClone'
import utils from '../utils/utils'
export default {
  name: 'equipmentCalibration',
  components: {
    MetaTreeList,
    MetaNumberInput,
    MetaPageTable
  },
  data () {
    return {
      equipmentOptionDialog: false,
      calibrationInfoDialog: false,
      echartDialog: false,
      dbDataImportFlag: false,
      dbDataFileList: [],
      dbDataImportUrl: '',
      token: localStorage.getItem("token"),
      echartLoading: false,
      equipmentOption: {
        cjTimes: 1,
        remark: ''
      },
      calibrationTableData: {},
      btnClickType: '',
      roleInfoItem: {},
      treeIcon: require("@/assets/images/v4/equipmentTreeIcon.png"),
      ws: null,
      username: '',
      dnChart: null,
      reflectivityChart: null,
      defaultProps: {
        children: 'list',
        label: 'name'
      },
      equTreeData: [],
      dsType: '10', // 10 - 连续采集 ，20 - 设置采集次数
      equipmentStatusNow: '0',
      lightSource: '2', // 1开2关
      workModel: '00', //全功率模式
      realWorkModel: '',
      voltageDown: 9, //电压阈值
      voltageUp: 10, //电压阈值
      equipmentParams: {
        visible_light_integral: 0,
        shot_wave_integral: 0,
        fill_lamp_voltage: 0,
        data_value_gain: 0,
        power_supply_bias: 0
      },
      collectionType: 0,
      equipmentOnType: '', //1在线2调试3维修4报警
      equipmentVoltage: '', //设备电量
      electricityBackup:'',//备用电池电压
      xmStatus: '',
      darkCurrentInCalculation: false,
      dbxsType: '0',
      equipmentOptionRules: {
        cjTimes: [
          { required: true, message: '请输入采集次数', trigger: 'blur' },
        ]
      },
      bzbOriginalChart: null,
      bzbHandleChart: null,
      adlOriginalChart: null,
      adlHandleChart: null,
      ecDetailBtnGroup: [{
        id: "import",
        title: "导入定标数据",
      },{
        id: "export",
        title: "导出定标数据",
      }],
      displayItem: [
        {
          label: '积分时间',
          prop: 'visible_light_integral'
        },
        {
          label: '增益',
          prop: 'data_value_gain'
        },
        {
          label: '最新定标时间',
          prop: 'update_time'
        },
        {
          label: '标准板',
          prop: 'hasBzb',
          type: 'if',
          format: {
            '1': "完成"
          },
          color: {
            '1': 'green'
          }
        },
        {
          label: '暗电流',
          prop: 'hasAdl',
          type: 'if',
          format: {
            '1': "完成"
          },
          color: {
            '1': 'green'
          }
        },
        {
          label: '应用于采集',
          prop: 'apply',
          type: 'if',
          format: {
            '1': "是"
          }
        }
      ],
      lineBtnGroup: [
        {
          id: 'use',
          title: '应用',
          hideCheck: this.btnHidecheck,
        },
        {
          id: 'unUse',
          title: '取消应用',
          hideCheck: this.btnHidecheck,
        },
        {
          id: 'chart',
          title: '曲线'
        },
        {
          id: 'delete',
          title: '删除',
          hideCheck: this.btnHidecheck,
        }
      ],
    }
  },
  created() {
    this.initWebsocket()
  },
  mounted() {
    this.initEquipmentData()
  },
  destroyed() {
    if(this.ws) {
      this.ws.close()
      this.ws = null
    }
  },
  methods: {
    initWebsocket() {
      let _this = this
      _this.username = localStorage.getItem('username')
      if ('WebSocket' in window) {
        // 打开一个 web socket
        let ws = new WebSocket(process.env.PROGOO_SOCKET + `ws/${_this.username}`)
        _this.ws = ws
        ws.onopen = function() {
          // Web Socket 已连接上，使用 send() 方法发送数据
          _this.$message({
            message: '设备通讯连接成功',
            type: 'success'
          });
        }
        ws.onmessage = function(evt) {
          try {
            let msg = JSON.parse(evt.data)
            _this.websocketMsgHandle(msg)
          } catch (error) {
            console.log('不是个json对象')
          }
        }
        ws.onclose = function() {
          // 关闭 websocket
        }
        ws.onerror = function() {
          _this.$message.error('设备通讯连接已断开')
        }
      } else {
        // 浏览器不支持 WebSocket
        alert('您的浏览器不支持 WebSocket!')
      }
    },
    websocketMsgHandle(msg) {
      console.log(msg)
      if(msg.type === 13) {
        if(msg.fixed_type_list && msg.fixed_type_list.length > 0) {
          if(msg.fixed_type_list[0].equipmentId === this.roleInfoItem.id) {
            // 1连续采集关，2连续采集开，3样品采集，4暗电流，5标准板，6定时关，7定时开
            if(msg.fixed_type_list[0].panel_parameters.collectionType == '2' || msg.fixed_type_list[0].panel_parameters.collectionType == '3' || msg.fixed_type_list[0].panel_parameters.collectionType == '4' || msg.fixed_type_list[0].panel_parameters.collectionType == '5' || msg.fixed_type_list[0].panel_parameters.collectionType == '7') {
              this.equipmentStatusNow = '10'
            }else {
              this.equipmentStatusNow = '20'
            }
            this.collectionType = msg.fixed_type_list[0].panel_parameters.collectionType
            this.equipmentOnType = msg.fixed_type_list[0].panel_parameters.onType
            this.xmStatus = msg.fixed_type_list[0].panel_parameters.xmStatus

            this.lightSource = msg.fixed_type_list[0].panel_parameters.light_source
            this.realWorkModel = msg.fixed_type_list[0].panel_parameters.lastCjModelStatus
          }
        }
      }else if(msg.type === 100) {
        let showData = {}
        if(msg.equipment_type !== '2') {
          showData = msg.fixed_type_list.length > 0 ? msg.fixed_type_list[0] : {}
        }
        if(Object.keys(showData).length > 0) {
          if(showData.equipmentId === this.roleInfoItem.id) {
            for(let i in showData.dataList) {
              let selectItem = {}
              selectItem.value = showData.dataList[i].value
              selectItem.name = showData.dataList[i].name
              selectItem.xData = showData.centralWavelength
              selectItem.yData = showData.dataList[i].arr
              this.chartInit(selectItem)
            }
          }
        }
      }
    },
    initEquipmentData() {
      this.$fetch({
        url: process.env.PROGOO_GATE_WATER + "admin/equipment/userarea",
        method: "post",
        data: {}
      }).then(res => {
        if (res.data.code === 200) {
          this.equTreeData = res.data.result
          let currentDataItem = {}
          for(let i in this.equTreeData) {
            this.equTreeData[i].name = "(" + this.equTreeData[i].area_jc + ")" + this.equTreeData[i].area_name
            this.equTreeData[i].level = 1
            for(let j in this.equTreeData[i].list) {
              if(this.equTreeData[i].list[j].customizeName && this.equTreeData[i].list[j].customizeName !== '') {
                this.equTreeData[i].list[j].name = this.equTreeData[i].list[j].customizeName
              }else {
                this.equTreeData[i].list[j].name = this.equTreeData[i].list[j].equipmentname
              }
              this.equTreeData[i].list[j].level = 2
              for(let key in this.equTreeData[i].list[j].equipmentRecord) {
                //子表中的这些参数不正确，不加入主表。
                if(key === 'aid' || key === 'id' || key === 'eid' || key === 'snid' || key === 'equipment_type') {
                  continue
                }
                this.equTreeData[i].list[j][key] = this.equTreeData[i].list[j].equipmentRecord[key]
              }
              if(Object.keys(this.roleInfoItem).length > 0 && this.roleInfoItem.id === this.equTreeData[i].list[j].id){
                currentDataItem = this.equTreeData[i].list[j]
              }
            }
          }
          if(Object.keys(currentDataItem).length > 0) {
            this.roleInfoItem = deepClone(currentDataItem)
            this.darkCurrentInCalculation = this.roleInfoItem.equipmentRecord.adlType
            this.dbxsType = this.roleInfoItem.equipmentRecord.dbxsType

            this.getEqtInfo((status,result) => {
              if(status) {
                // collectionType 1连续采集关，2连续采集开，3样品采集，4暗电流，5标准板，6定时关，7定时开
                if(result.collectionType == '2' || result.collectionType == '3' || result.collectionType == '4' || result.collectionType == '5' || result.collectionType == '7') {
                  this.equipmentStatusNow = '10'
                }else {
                  this.equipmentStatusNow = '20'
                }
                this.collectionType = result.collectionType
                this.equipmentOnType  = result.onType
                this.xmStatus = result.equipmentParams.xmStatus

                this.lightSource = result.collectionParams.lightSource
                this.equipmentParams = deepClone(result.equipmentParams)

                this.equipmentVoltage = result.equipmentParams.electricity && result.equipmentParams.electricity !== '' ? parseFloat(result.equipmentParams.electricity).toFixed(2) : 0
                this.electricityBackup = result.equipmentParams.electricityBackup&&result.equipmentParams.electricityBackup !==''?parseFloat(result.equipmentParams.electricityBackup).toFixed(2):0

                this.dsType = result.collectionParams.frequency == 0 ? '10' : '20'

                //版本3.1只支持全休眠模式 3.0支持半休眠模式
                let recommendModel = ''
                if(this.roleInfoItem.version) {
                  if(this.roleInfoItem.version == '3.0') {
                    recommendModel = '03'
                  }else if(this.roleInfoItem.version == '3.1') {
                    recommendModel = '02'
                  }else {
                    recommendModel = '00'
                  }
                }
                
                this.workModel = result.equipmentParams.cjModel ? result.equipmentParams.cjModel : recommendModel
                if(this.collectionType == '7' && this.workModel == '03') {
                  this.realWorkModel = result.equipmentParams.lastCjModelStatus ? result.equipmentParams.lastCjModelStatus : ''
                }
                this.voltageUp = result.equipmentParams.voltageUp ? result.equipmentParams.voltageUp : 10
                this.voltageDown = result.equipmentParams.voltageDown ? result.equipmentParams.voltageDown : 9
                
              }else {
                this.equipmentParams = {
                  visible_light_integral: 0,
                  shot_wave_integral: 0,
                  fill_lamp_voltage: 0,
                  data_value_gain: 0,
                  power_supply_bias: 0
                }
              }
            })

          }else {
            this.roleInfoItem = {}
          }
          // this.$nextTick(() => {
          //   this.$refs.equipmentCalibration_list.setChoiceRole(this.roleInfoItem)
          // })

          
        }else {
          this.$notify.error({
            title: '错误',
            message: res.data.message
          });
        }
      })
    },
    roloeItemChoose(item) {
      if(item.level === 1) {
        return
      }
      this.roleInfoItem = {}
      this.equipmentVoltage = ''
      this.electricityBackup=''
      this.$nextTick(() => {
        this.roleInfoItem = deepClone(item)
        this.darkCurrentInCalculation = this.roleInfoItem.equipmentRecord.adlType
        this.dbxsType = this.roleInfoItem.equipmentRecord.dbxsType
        this.getEqtInfo((status,result) => {
          if(status) {
            // 1连续采集关，2连续采集开，3样品采集，4暗电流，5标准板，6定时关，7定时开
            if(result.collectionType == '2' || result.collectionType == '3' || result.collectionType == '4' || result.collectionType == '5' || result.collectionType == '7') {
              this.equipmentStatusNow = '10'
            }else {
              this.equipmentStatusNow = '20'
            }
  
            this.collectionType = result.collectionType
            this.equipmentOnType  = result.onType
  
            this.lightSource = result.collectionParams.lightSource
            this.equipmentParams = deepClone(result.equipmentParams)

            this.xmStatus = result.equipmentParams.xmStatus

            this.equipmentVoltage = result.equipmentParams.electricity && result.equipmentParams.electricity !== '' ? parseFloat(result.equipmentParams.electricity).toFixed(2) : 0
            this.electricityBackup = result.equipmentParams.electricityBackup&& result.equipmentParams.electricityBackup !==''?parseFloat(result.equipmentParams.electricityBackup).toFixed(2) : 0
            console.log(parseFloat(result.equipmentParams.electricity).toFixed(2))
  
            this.dsType = result.collectionParams.frequency == 0 ? '10' : '20'
  
            //版本3.1只支持全休眠模式 3.0支持半休眠模式
            let recommendModel = ''
            if(this.roleInfoItem.version) {
              if(this.roleInfoItem.version == '3.0') {
                recommendModel = '03'
              }else if(this.roleInfoItem.version == '3.1') {
                recommendModel = '00'
              }else {
                recommendModel = '02'
              }
            }
            
            this.workModel = result.equipmentParams.cjModel ? result.equipmentParams.cjModel : recommendModel
            
            if(this.collectionType == '7' && this.workModel == '03') {
              this.realWorkModel = result.equipmentParams.lastCjModelStatus ? result.equipmentParams.lastCjModelStatus : ''
            }
            this.voltageUp = result.equipmentParams.voltageUp ? result.equipmentParams.voltageUp : 10
            this.voltageDown = result.equipmentParams.voltageDown ? result.equipmentParams.voltageDown : 9
  
          }else{
            this.equipmentParams = {
              visible_light_integral: 0,
              shot_wave_integral: 0,
              fill_lamp_voltage: 0,
              data_value_gain: 0,
              power_supply_bias: 0
            }
          }
        })
      })
    },
    getEqtInfo(callback) {
      this.$fetch({
        url: process.env.PROGOO_GATE_WATER + "admin/equipment/getEqtInfo?snid=" + this.roleInfoItem.snid,
        method: "post",
        data: {}
      }).then(res => {
        if (res.data.code === 200) {
          if(res.data.result.code && res.data.result.code == 400) {
            this.$notify.error({
              title: '错误',
              message: res.data.result.message
            });
            this.equipmentStatusNow = '0'
            callback(false)
          }else {
            if(callback && typeof(callback) === 'function') {
              callback(true, res.data.result)
            }
          }
        }else {
          this.$notify.error({
            title: '错误',
            message: res.data.message
          });
        }
      })
    },
    checkEqtStatus() {
      this.getEqtInfo((status,result) => {
        if(status) {
          // collectionType 1连续采集关，2连续采集开，3样品采集，4暗电流，5标准板，6定时关，7定时开
          if(result.collectionType == '2' || result.collectionType == '3' || result.collectionType == '4' || result.collectionType == '5' || result.collectionType == '7') {
            this.equipmentStatusNow = '10'
          }else {
            this.equipmentStatusNow = '20'
          }
          this.collectionType = result.collectionType
          this.equipmentOnType  = result.onType
          this.xmStatus = result.equipmentParams.xmStatus

          this.lightSource = result.collectionParams.lightSource
        }
      })
    },
    closeEquipment() {
      /**
       * 断电关机（主电源未连接可关机，主电源连接时自动开机）
       */
      this.$confirm('请确认主电源未连接，否则无法执行关机操作。', '确认现在将设备关机吗？', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.getEqtInfo((status,result) => {
          if(status) {
            let msgJson = {
              sn_id: this.roleInfoItem.snid,
              command: 'close',
            }
            this.$fetch({
              url: process.env.PROGOO_GATE_WATER + "admin/equipment/sendCommand",
              method: "post",
              data: msgJson
            }).then(res => {
              if (res.data.code === 200) {
                this.$message({
                  message: res.data.result,
                  type: 'success'
                });
              }else {
                this.$notify.error({
                  title: '错误',
                  message: res.data.message
                });
              }
            })
          }
        })
      })
    },
    doOpenLock() {
      //电磁锁开锁
      this.$confirm('是否确认开启电磁锁？请避免误操作。（电磁锁开启后会在10秒后自动关闭）', '确认开启电磁锁', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.getEqtInfo((status,result) => {
          if(status) {
            let msgJson = {
              snid: this.roleInfoItem.snid,
              type: 'open',
            }
            this.$fetch({
              url: process.env.PROGOO_GATE_WATER + "admin/equipment/control?userName=" + localStorage.getItem("username"),
              method: "post",
              data: msgJson
            }).then(res => {
              if (res.data.code === 200) {
                this.$message({
                  message: '操作成功',
                  type: 'success'
                });
              }else {
                this.$notify.error({
                  title: '错误',
                  message: res.data.message
                });
              }
            })
          }
        })
      })
    },
    doOption() {
      this.getEqtInfo((status,result) => {
        if(status) {
          // 1连续采集关，2连续采集开，3样品采集，4暗电流，5标准板，6定时关，7定时开
          let equipmentStatusNow = ''
          // 00 在线 10半休眠 20全休眠
          let xmStatus = result.equipmentParams.xmStatus && result.equipmentParams.xmStatus != '' ? result.equipmentParams.xmStatus : ''
          if(result.onType == '2') {
            this.$notify({
              title: '警告',
              message: '当前设备不在线，请稍后再试',
              type: 'warning'
            });
            return
          }
          
          if(result.collectionType == '2' || result.collectionType == '3' || result.collectionType == '4' || result.collectionType == '5' || result.collectionType == '7') {
            equipmentStatusNow = '10'
          }else {
            equipmentStatusNow = '20'
          }
          if(equipmentStatusNow !== '20') {
            this.$notify({
              title: '警告',
              message: '当前设备正在采集，请刷新状态，稍后再试',
              type: 'warning'
            });
            return
          }else {
            if(parseFloat(this.roleInfoItem.version) >= 3) {
              if(xmStatus == '10') {
                this.$notify({
                  title: '警告',
                  message: '当前设备正在休眠唤醒中，请稍后再试',
                  type: 'warning'
                });
                return
              }else if(xmStatus == '20') {
                this.$notify({
                  title: '警告',
                  message: '当前设备正在充电，请稍后再试',
                  type: 'warning'
                });
                return
              }
            }
          }
          if(this.btnClickType == 'params') {
            this.$confirm('确认变更设备参数？', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
              let is_data_value_gain = '0'
              let is_fill_lamp_voltage = '0'
              let is_power_supply_bias = '0'
              let is_shot_wave_integral = '0'
              let is_visible_light_integral = '0'
              if(this.equipmentParams.visible_light_integral != result.equipmentParams.visible_light_integral) {
                is_visible_light_integral = '1'
              }
              if(this.equipmentParams.fill_lamp_voltage != result.equipmentParams.fill_lamp_voltage) {
                is_fill_lamp_voltage = '1'
              }
              if(this.equipmentParams.shot_wave_integral != result.equipmentParams.shot_wave_integral) {
                is_shot_wave_integral = '1'
              }
              if(this.equipmentParams.data_value_gain != result.equipmentParams.data_value_gain) {
                is_data_value_gain = '1'
              }
              if(this.equipmentParams.power_supply_bias != result.equipmentParams.power_supply_bias) {
                is_power_supply_bias = '1'
              }

              this.$fetch({
                url: process.env.PROGOO_GATE_WATER + "admin/equipment/infoEdit",
                method: "post",
                data: {
                  snid: this.roleInfoItem.snid,
                  data_value_gain: this.equipmentParams.data_value_gain,
                  fill_lamp_voltage: this.equipmentParams.fill_lamp_voltage,
                  power_supply_bias: this.equipmentParams.power_supply_bias,
                  shot_wave_integral: this.equipmentParams.shot_wave_integral,
                  visible_light_integral: this.equipmentParams.visible_light_integral,
                  is_data_value_gain: is_data_value_gain,
                  is_fill_lamp_voltage: is_fill_lamp_voltage,
                  is_power_supply_bias: is_power_supply_bias,
                  is_shot_wave_integral: is_shot_wave_integral,
                  is_visible_light_integral: is_visible_light_integral
                }
              }).then(res => {
                if(res.data.code == 200) {
                  this.$message({
                    message: '保存成功',
                    type: 'success'
                  });
                }
              })
            })
          }else if(this.btnClickType == 'dc' || this.btnClickType == 'bzb' || this.btnClickType == 'adl') {
            let msgJson = {
              snid: this.roleInfoItem.snid,
              type: this.btnClickType,
              seconds: 2,//开灯时间  2.4以下版本设备使用
              version: this.roleInfoItem.version,
              remark: this.equipmentOption.remark,
              cjModel: '00'
            }
            if(this.btnClickType == 'dc') {
              msgJson.times = this.equipmentOption.cjTimes && this.equipmentOption.cjTimes !== '' && this.equipmentOption.cjTimes !== 0 ? this.equipmentOption.cjTimes : 5
            }else if(this.btnClickType == 'bzb') {
              msgJson.dbTimes = this.equipmentOption.cjTimes && this.equipmentOption.cjTimes !== '' && this.equipmentOption.cjTimes !== 0 ? this.equipmentOption.cjTimes : 5
            }else if(this.btnClickType == 'adl') {
              msgJson.dbTimes = this.equipmentOption.cjTimes && this.equipmentOption.cjTimes !== '' && this.equipmentOption.cjTimes !== 0 ? this.equipmentOption.cjTimes : 5
            }
            this.editDialogClose()
            this.$fetch({
              url: process.env.PROGOO_GATE_WATER + "admin/equipment/control?userName=" + localStorage.getItem("username"),
              method: "post",
              data: msgJson
            }).then(res => {
              if (res.data.code === 200) {
                this.$message({
                  message: '操作成功',
                  type: 'success'
                });
                this.checkEqtStatus()
              }else {
                this.$notify.error({
                  title: '错误',
                  message: res.data.message
                });
              }
            })
          }
        }
      })
    },
    stopDcOption() {
      this.$confirm('确认停止采集？如果设备正在采集会完成当前采集后自动停止', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let msgJson = {
          snid: this.roleInfoItem.snid,
          type: 'stop',
          version: this.roleInfoItem.version,
        }
        this.$fetch({
          url: process.env.PROGOO_GATE_WATER + "admin/equipment/control?userName=" + localStorage.getItem("username"),
          method: "post",
          data: msgJson
        }).then(res => {
          if (res.data.code === 200) {
            this.$message({
              message: '操作成功',
              type: 'success'
            });
            this.checkEqtStatus()
          }else {
            this.$notify.error({
              title: '错误',
              message: res.data.message
            });
          }
        })
      })
    },
    stopDsOption() {
      this.$confirm('确认停止定时采集？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let msgJson = {
          snid: this.roleInfoItem.snid,
          type: 'timeStop',
          version: this.roleInfoItem.version,
        }
        this.$fetch({
          url: process.env.PROGOO_GATE_WATER + "admin/equipment/control?userName=" + localStorage.getItem("username"),
          method: "post",
          data: msgJson
        }).then(res => {
          if (res.data.code === 200) {
            this.$message({
              message: '操作成功',
              type: 'success'
            });
            this.checkEqtStatus()
          }else {
            this.$notify.error({
              title: '错误',
              message: res.data.message
            });
          }
        })
      })
    },
    equipmentParamsRefresh() {
      // 获取设备参数信息（可见光积分、补光灯电压、短波积分、增益、偏压）LDC
      this.$fetch({
        url: process.env.PROGOO_GATE_WATER + "admin/equipment/infoBySid",
        method: "post",
        data: {
          snid: this.roleInfoItem.snid
        }
      }).then(res => {
        if(res.data.code == 200) {
          if(res.data.result.code && res.data.result.code == 400) {
            this.$notify.error({
              title: '错误',
              message: res.data.result.message
            });
            this.equipmentParams = {
              visible_light_integral: 0,
              shot_wave_integral: 0,
              fill_lamp_voltage: 0,
              data_value_gain: 0,
              power_supply_bias: 0
            }
            return
          }
          this.equipmentParams.visible_light_integral = res.data.result.visible_light_integral ? res.data.result.visible_light_integral : 0
          this.equipmentParams.fill_lamp_voltage = res.data.result.fill_lamp_voltage ? res.data.result.fill_lamp_voltage : 0
          this.equipmentParams.shot_wave_integral = res.data.result.shot_wave_integral ? res.data.result.shot_wave_integral : 0
          this.equipmentParams.data_value_gain = res.data.result.data_value_gain ? res.data.result.data_value_gain : 0
          this.equipmentParams.power_supply_bias = res.data.result.power_supply_bias ? res.data.result.power_supply_bias : 0
          this.$message({
            message: '获取成功',
            type: 'success'
          });
        }else {
          this.$notify.error({
            title: '错误',
            message: res.data.message
          });
        }
      })
    },
    doParamsOption(key) {
      this.btnClickType = key
      this.doOption()
    },
    openDialog(key) {
      this.btnClickType = key
      this.equipmentOptionDialog = true
    },
    editDialogClose() {
      this.equipmentOptionDialog = false
      this.equipmentOption = {
        cjTimes: 0,
        remark: ''
      }
    },
    editDialogSubmit() {
      this.$refs['equipmentOption_form'].validate((valid) => {
        if (valid) {
          this.doOption()
        } else {
          return false;
        }
      });
      
    },
    openCalibrationInfo() {
      this.calibrationRecordTable(true,() => {
        this.calibrationInfoDialog = true
      })
    },
    calibrationRecordTable(reflash,callback) {
      this.$fetch({
        url: process.env.PROGOO_GATE_WATER + "dbRecord/selectByEquipmentId",
        method: "get",
        params: {
          "id": this.roleInfoItem.id,
        }
      }).then(res => {
        if (res.data.code === 200) {
          if(callback && typeof callback === 'function') {
            callback()
          }          
          this.calibrationTableData = {}
          this.calibrationTableData.page = 1
          this.calibrationTableData.total = 1
          this.calibrationTableData.totalElements = res.data.result.length
          this.calibrationTableData.content = []
          for(let i in res.data.result) {
            let item = res.data.result[i]
            if(item.adl_db_id && item.adl_db_id !== '') {
              item.hasAdl = "1"
            }else {
              item.hasAdl = "0"
            }
            if(item.bzb_db_id && item.bzb_db_id !== '') {
              item.hasBzb = "1"
            }else {
              item.hasBzb = "0"
            }
            this.calibrationTableData.content.push(item)
          }
          this.$nextTick(() => {
            this.$refs.calibrationInfoTable.formDataInit(reflash)
          })

        }else {
          this.$notify.error({
            title: '错误',
            message: res.data.message
          });
        }
      })
    },
    voltageDownChange(value) {
      if(this.voltageUp < value) {
        this.voltageUp = value
      }
    },
    btnHidecheck(rowData, item) {
      if(!(rowData.hasAdl === "1" && rowData.hasBzb === "1" && rowData.apply == '1') && item.id === "use") {
        return true;
      }
      if(rowData.apply == '1' && item.id === 'unUse') {
        return true;
      }
      if(rowData.apply != '1' && item.id === 'delete') {
        return true;
      }
      return false;
    },
    tableBtnClick(item) {
      if(item.button === 'import') { //导入
        this.$confirm("定标数据会影响数据结果，请反复确认数据", "确认导入定标数据?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }).then(() => {
          this.dbDataFileList = [];
          this.dbDataImportUrl = process.env.PROGOO_GATE_WATER + "dbRecord/import";
          this.dbDataImportFlag = true;
        });
      }else if(item.button === 'export') { //导出
        let token = localStorage.getItem("token");
        this.axios({
          method: "get",
          url: process.env.PROGOO_GATE_WATER + "dbRecord/download",
          params: {
            id: this.roleInfoItem.id
          },
          headers: {
            "x-auth-token": token,
          },
          responseType: "blob",
        }).then((res) => {
          if (res.data.code && res.data.code == 400) {
            this.$notify.error({
              title: "错误",
              message: res.data.message,
            });
            return;
          }
          const url = window.URL.createObjectURL(new Blob([res.data]));
          const link = document.createElement("a");
          link.style.display = "none";
          link.href = url;
          link.setAttribute("download", "定标数据.txt");
          document.body.appendChild(link);
          link.click();
          document.body.removeChild(link);
        })
      }
    },
    beforeUpload(file) {
      let excelfileExtend = ".txt"; //设置文件格式
      let fileExtend = file.name.substring(file.name.lastIndexOf(".")).toLowerCase();
      if (excelfileExtend.indexOf(fileExtend) <= -1) {
        this.dbDataFileList = [];
        this.$message.error("文件格式错误");
        return;
      }
    },
    uploadSuccess(response, file, fileList) {
      if (response.code === 200) {
        this.dbDataFileList = [];
        this.$notify({
          title: "成功",
          message: "导入成功",
          type: "success",
        });
        this.dbDataImportFlag = false;
        this.calibrationRecordTable(true)
      } else {
        this.dbDataFileList = [];
        this.$notify.error({
          title: "错误",
          message: response.message,
        });
      }
    },
    tableInlineBtnClick(item) {
      if (item.button === "use") {
        this.$confirm('定标数据操作需慎重，是否确认应用当前定标数据', '确认应用？', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$fetch({
            url: process.env.PROGOO_GATE_WATER + "/dbRecord/apply",
            method: "post",
            data: {
              "id": item.rows.id,
              "apply": "1",
            }
          }).then(res => {
            if (res.data.code === 200) {
              this.$message({
                message: '保存成功',
                type: 'success'
              });
              this.calibrationRecordTable(false)
            }else {
              this.$notify.error({
                title: '错误',
                message: res.data.message
              });
            }
          })
        })

      }else if (item.button === "unUse") {
        this.$confirm('定标数据操作需慎重，是否确认取消应用当前定标数据', '确认取消应用？', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$fetch({
            url: process.env.PROGOO_GATE_WATER + "/dbRecord/apply",
            method: "post",
            data: {
              "id": item.rows.id,
              "apply": "0",
            }
          }).then(res => {
            if (res.data.code === 200) {
              this.$message({
                message: '保存成功',
                type: 'success'
              });
              this.calibrationRecordTable(false)
            }else {
              this.$notify.error({
                title: '错误',
                message: res.data.message
              });
            }
          })
        })
      }else if (item.button === "chart") {
        this.echartDialog = true
        this.echartLoading = true
        this.$fetch({
          url: process.env.PROGOO_GATE_WATER + "/dbRecord/selectDbDataById",
          method: "get",
          params: {
            "id": item.rows.id,
          }
        }).then(res => {
          if (res.data.code === 200) {
            this.initMoreEchart(res.data.result);
          }else {
            this.$notify.error({
              title: '错误',
              message: res.data.message
            });
          }
        })
      }else if (item.button === "delete") {
        this.$confirm('定标数据操作需慎重，是否确认删除当前定标数据', '确认删除？', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$fetch({
            url: process.env.PROGOO_GATE_WATER + "/dbRecord/delete",
            method: "get",
            params: {
              "id": item.rows.id,
            }
          }).then(res => {
            if (res.data.code === 200) {
              this.$message({
                message: '删除成功',
                type: 'success'
              });
              this.calibrationRecordTable(false)
            }else {
              this.$notify.error({
                title: '错误',
                message: res.data.message
              });
            }
          })
        })
      }
    },
    saveCalibrationParams() {
      // 保存参数
      this.$confirm('是否确认保存当前配置参数', '确认保存？', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$fetch({
          url: process.env.PROGOO_GATE_WATER + "admin/equipment/updateRecord",
          method: "post",
          data: {
            "equipment_id": this.roleInfoItem.id,
            "voltage_down": this.voltageDown,
            "voltage_up": this.voltageUp,
            "adl_type": this.darkCurrentInCalculation,
            "dbxs_type": this.dbxsType
          }
        }).then(res => {
          if (res.data.code === 200) {
            this.$message({
              message: '保存成功',
              type: 'success'
            });
            this.initEquipmentData()
          }else {
            this.$notify.error({
              title: '错误',
              message: res.data.message
            });
          }
        })
      })
    },
    initMoreEchart(itemDatas) {
      let waveLength = this.roleInfoItem.wavelength.split(',')
      let bzbFinialDatas = []
      let adlFinialDatas = []
      let bzbDatas = []
      let adlDatas = []
      for(let i in itemDatas) {
        if(itemDatas[i].type === 'bzb') {
          bzbFinialDatas = itemDatas[i].dn_data.split(',')
          for(let j in itemDatas[i].list) {
            let seriesTemp = {
              name: itemDatas[i].list[j].collect_time,
              type: "line",
              smooth: true,
              data: itemDatas[i].list[j].dn_data.split(','),
            };
            bzbDatas.push(seriesTemp)
          }
        }else if(itemDatas[i].type === 'adl') {
          adlFinialDatas = itemDatas[i].dn_data.split(',')
          for(let j in itemDatas[i].list) {
            let seriesTemp = {
              name: itemDatas[i].list[j].collect_time,
              type: "line",
              smooth: true,
              data: itemDatas[i].list[j].dn_data.split(','),
            };
            adlDatas.push(seriesTemp)
          }
        }
      }
      let echarts = require("echarts");
      let chartDocBZBOriginal = document.getElementById("echartForCalibration_bzbOriginal");
      this.bzbOriginalChart = echarts.init(chartDocBZBOriginal);
      this.bzbOriginalChart.setOption({
        title: {
          text: '标准板原始光谱',
          x:'28',
          y:'8',
          textStyle: {
            color: '#000',
            fontWeight: 'normal',
            fontSize: '18'
          }
        },
        grid: {
          left: "10%",
          bottom: "5%",
          top: "15%",
          height: "80%",
          right: "2%",
          show: true,
          // containLabel: true
        },
        xAxis: {
          type: "category",
          axisLabel: {
            show: true,
            fontSize: 10,
          },
          boundaryGap: false,
          data: waveLength,
        },
        yAxis: {
          type: "value",
          axisLabel: {
            show: true,
            fontSize: 10,
          },
          scale: true,
        },
        series: bzbDatas,
      });
      let chartDocBZBHandle = document.getElementById("echartForCalibration_bzbHandle");
      this.bzbHandleChart = echarts.init(chartDocBZBHandle);
      this.bzbHandleChart.setOption({
        title: {
          text: '标准板聚类平均光谱',
          x:'28',
          y:'8',
          textStyle: {
            color: '#000',
            fontWeight: 'normal',
            fontSize: '18'
          }
        },
        grid: {
          left: "10%",
          bottom: "5%",
          top: "15%",
          height: "80%",
          right: "2%",
          show: true,
          // containLabel: true
        },
        xAxis: {
          type: "category",
          axisLabel: {
            show: true,
            fontSize: 10,
          },
          boundaryGap: false,
          data: waveLength,
        },
        yAxis: {
          type: "value",
          axisLabel: {
            show: true,
            fontSize: 10,
          },
          scale: true,
        },
        series: [{
          name: "聚类平均",
          type: "line",
          smooth: true,
          data: bzbFinialDatas,
        }],
      });
      let chartDocADLOriginal = document.getElementById("echartForCalibration_adlOriginal");
      this.adlOriginalChart = echarts.init(chartDocADLOriginal);
      this.adlOriginalChart.setOption({
        title: {
          text: '暗电流原始光谱',
          x:'28',
          y:'8',
          textStyle: {
            color: '#000',
            fontWeight: 'normal',
            fontSize: '18'
          }
        },
        grid: {
          left: "10%",
          bottom: "5%",
          top: "15%",
          height: "80%",
          right: "2%",
          show: true,
          // containLabel: true
        },
        xAxis: {
          type: "category",
          axisLabel: {
            show: true,
            fontSize: 10,
          },
          boundaryGap: false,
          data: waveLength,
        },
        yAxis: {
          type: "value",
          axisLabel: {
            show: true,
            fontSize: 10,
          },
          scale: true,
        },
        series: adlDatas,
      });
      let chartDocADLHandle = document.getElementById("echartForCalibration_adlHandle");
      this.adlHandleChart = echarts.init(chartDocADLHandle);
      this.adlHandleChart.setOption({
        title: {
          text: '暗电流聚类平均光谱',
          x:'28',
          y:'8',
          textStyle: {
            color: '#000',
            fontWeight: 'normal',
            fontSize: '18'
          }
        },
        grid: {
          left: "10%",
          bottom: "5%",
          top: "15%",
          height: "80%",
          right: "2%",
          show: true,
          // containLabel: true
        },
        xAxis: {
          type: "category",
          axisLabel: {
            show: true,
            fontSize: 10,
          },
          boundaryGap: false,
          data: waveLength,
        },
        yAxis: {
          type: "value",
          axisLabel: {
            show: true,
            fontSize: 10,
          },
          scale: true,
        },
        series: [{
          name: "聚类平均",
          type: "line",
          smooth: true,
          data: adlFinialDatas,
        }],
      });
      
      this.$nextTick(() => {
        this.bzbOriginalChart.resize();
        this.bzbHandleChart.resize();
        this.adlOriginalChart.resize();
        this.adlHandleChart.resize();
        this.echartLoading = false
      });
    },
    chartInit(data) {
      let echarts = require('echarts')
      if(data.value === 'dnValue') {
        if(this.$refs['dnChart']) {
          this.dnChart = echarts.init(this.$refs['dnChart'])
          this.dnChart.setOption({
            title: {
              text: 'DN值曲线',
              x:'28',
              y:'8',
              textStyle: {
                color: '#000',
                fontWeight: 'normal',
                fontSize: '18'
              }
            },
            color: ['#F28F9B'],
            tooltip: {
              trigger: 'axis'
            },
            grid: {
              left: '6%',
              bottom: '7%',
              top: '18%',
              height: '70%',
              right: '2%',
              show: true,
              // backgroundColor: '#002738'
              // containLabel: true
            },
            xAxis: {
              type: 'category',
              axisLine: {
                lineStyle: {
                  color: '#000',
                }
              },
              axisLabel: {
                show: true,
                fontSize: 10
              },
              boundaryGap: false,
              data: data.xData
            },
            yAxis: {
              type: 'value',
              axisLine: {
                lineStyle: {
                  color: '#000'
                }
              },
              axisLabel: {
                show: true,
                fontSize: 10
              },
              splitLine: {
                lineStyle: {
                    color: ['#DFEAFA']
                }
              },
              scale:true
            },
            series: [
              {
                name: data.name,
                type: 'line',
                stack: '总量',
                smooth: true,
                data: data.yData,
                // color: '#000',
                areaStyle: {
                  color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                    offset: 0,
                    color: 'rgba(248,208,137,0.3)'
                  }, {
                    offset: 1,
                    color: '#F8D089'
                  }])
                },
              }
            ]
          })
          this.$nextTick(() => {
            this.dnChart.resize()
          })
        }
        
      }else if(data.value === 'reflectivity') {
        this.reflectivityChart = echarts.init(this.$refs['reflectivityChart'])
        this.reflectivityChart.setOption({
          title: {
            text: '反射率曲线',
            x:'28',
            y:'8',
            textStyle: {
              color: '#000',
              fontWeight: 'normal',
              fontSize: '18'
            }
          },
          color: ['#9290FF'],
          tooltip: {
            trigger: 'axis'
          },
          grid: {
            left: '6%',
            bottom: '7%',
            top: '18%',
            height: '70%',
            right: '2%',
            show: true,
            // backgroundColor: '#002738'
            // containLabel: true
          },
          xAxis: {
            type: 'category',
            axisLine: {
              lineStyle: {
                color: '#000',
              }
            },
            axisLabel: {
              show: true,
              fontSize: 10
            },
            boundaryGap: false,
            data: data.xData
          },
          yAxis: {
            type: 'value',
            axisLine: {
              lineStyle: {
                color: '#000'
              }
            },
            axisLabel: {
              show: true,
              fontSize: 10
            },
            splitLine: {
              lineStyle: {
                  color: ['#DFEAFA']
              }
            },
            scale:true
          },
          series: [
            {
              name: data.name,
              type: 'line',
              stack: '总量',
              smooth: true,
              data: data.yData,
              areaStyle: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                  offset: 0,
                  color: 'rgba(162,203,250,0.3)'
                }, {
                  offset: 1,
                  color: '#A2CBFA'
                }])
              },
            }
          ]
        })
        this.$nextTick(() => {
          this.reflectivityChart.resize()
        })
      }
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="less">
.equipmentCalibration{
  background-color: #EAECF0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-grow: 1;
  box-sizing: border-box;
  padding: 8px 0 8px 12px; 
  // overflow-y: scroll;
  .equipmentCalibration_treeBg {
    height: 100%;
    background-color: white;
    border-radius: 6px;
    margin-right: 12px;
  }
  .equipmentCalibration_infoBg {
    height: 100%;
    box-sizing: border-box;
    flex: 1;
    padding-right: 12px;
    overflow-x: scroll;
  }
  .equipmentCalibration_info {
    width: 100%;
    height: 100%;
    border: 1px solid rgb(228, 234, 236);
    flex: 1;
    min-width: 1360px;
    box-sizing: border-box;
    // background-color: white;
    // padding: 15px;
    .equipmentC_infoTitleBg {
      width: 100%;
      float: left;
      border-radius: 6px;
      // margin-top: 20px;
      padding-bottom: 10px;
      background-color: white;
      padding: 0 28px 10px;
      box-sizing: border-box;
      .equipmentC_infoTitle {
        font-size: 18px;
        float: left;
        height: 45px;
        line-height: 45px;
        width: 100%;
      }
      .equipmentC_infoContent {
        width: 100%;
        float: left;
        .equipmentC_infoItemBg {
          height: 20px;
          float: left;
          padding-left: 75px;
          display: flex;
          align-items: center;
          margin-bottom: 5px;
          .equipmentC_infoItemIconShowName {
            width: 16px;
            height: 16px;
          }
          .equipmentC_infoItemIconName {
            width: 16px;
            height: 16px;
          }
          .equipmentC_infoItemIconSnid {
            width: 16px;
            height: 16px;
          }
          .equipmentC_infoItemText {
            font-size: 16px;
            color: #999;
            margin-left: 8px;
          }
        }
      }
      .equipmentC_delBtn {
        float: right;
      }
    }
    .equipmentC_optionArea {
      width: 100%;
      float: left;
      padding: 10px 28px 30px 0;
      background-color: white;
      margin-top: 10px;
      border-radius: 6px;
      box-sizing: border-box;
      .equipmentC_optionTitle {
        font-size: 18px;
        float: left;
        height: 45px;
        line-height: 45px;
        width: 100%;
        box-sizing: border-box;
        padding-left: 28px;
      }
      .equipmentC_optionBg {
        width: 100%;
        display: flex;
        .equipmentC_left {
          width: 32%;
          position: relative; 
          .equipmentCLeft_water {
            width: 100%;
            margin-top: 70px;
          }
          .equipmentCLeft_equipment {
            width: 310px;
            position: absolute;
            left: 50%;
            margin-left: -155px;
            top: 60px;
          }
          .equipmentCLeft_equipment_o {
            width: 310px;
            position: absolute;
            left: 50%;
            margin-left: -155px;
            top: 60px;
            animation:pf 2.5s 0s linear infinite;
          }
          @keyframes pf {
            0% {
              transform: translateY(0px);
              // transform: rotate(0deg);
            }
            25% {
              transform: translateY(-1.5px); 
              // transform: rotate(1deg);
            }
            75% {
              transform: translateY(1.5px);
              // transform: rotate(-1deg);
            }
            100% {
              transform: translateY(0px);
              // transform: rotate(0deg);
            }
          }
          .equipmentCLeft_btnArea {
            width: 100%;
            height: 104px;
            position: absolute;
            left: 0;
            bottom: 10px;
            .equipmentCLeft_btn {
              width: 100%;
              height: 52px;
              box-sizing: border-box;
              padding-bottom: 10px;
              display: flex;
              justify-content: center;
              align-items: center;
              float: left;
              .equipmentCLeft_btnItem {
                width: 138px;
                height: 40px;
                border: 1px solid #999;
                margin: 0 6px;
                line-height: 40px;
                border-radius: 40px;
                text-align: center;
                font-size: 16px;
                color: #666;
                cursor: pointer;
                background: linear-gradient(180deg, #ffffff 0%, #ececec 100%);
              }
              .equipmentCLeft_btnItem:hover {
                color: white;
                background: linear-gradient(90deg, #409eff 0%, #40c7ff 100%);
                border-color: rgba(255,255,255,0);
              }
            }
          }
        }
        .equipmentC_right {
          width: 68%;
          display: flex;
          flex-direction: column;
          .equipmentC_btnGroup {
            width: 100%;
            height: 70px;
            .equipmentC_btn {
              float: right;
              margin-left: 12px;
            }
          }
          .equipmentC_settingArea {
            width: 100%;
            padding: 20px 18px 20px 0;
            box-sizing: border-box;
            border: 1px solid #909090;
            border-radius: 10px;
            margin-bottom: 16px;
            display: flex;
            .equipmentC_settingContent {
              flex: 1;
              .equipmentC_settingItem {
                float: left;
                display: flex;
                height: 40px;
                align-items: center;
                display: 42px;
                .equipmentC_settingTitle {
                  margin-right: 10px;
                  font-size: 18px;
                  margin-left: 24px;
                }
                .equipmentC_settingNumberInput {
                  width: 100px;
                  .el-input__inner {
                    width: 100px;
                    padding: 0 32px;
                  }
                }
                .equipmentC_settingSelect {
                  width: 100px;
                }
              }
            }
            .equipmentC_saveBtn {
              width: 88px;
              display: flex;
              align-items: center;
              justify-content: center;
              .equipmentC_save {
                width: 60px;
                height: 30px;
                line-height: 30px;
                font-size: 16px;
                border: 1px solid #999;
                color: #666;
                border-radius: 4px;
                cursor: pointer;
                background: linear-gradient(180deg, #ffffff 0%, #ececec 100%);
                text-align: center;
              }
              .equipmentC_save:hover {
                color: white;
                background: linear-gradient(90deg, #409eff 0%, #40c7ff 100%);
                border-color: rgba(255,255,255,0);
              }
            }
          }
          .equipmentC_paramArea {
            width: 100%;
            padding: 20px 18px 20px 24px; 
            box-sizing: border-box;
            border: 1px solid #909090;
            // float: left;
            flex: 1;
            border-radius: 10px;
            .equipmentC_paramTitle {
              float: left;
              font-size: 18px;
              width: 100%;
              display: flex;
              align-items: center;
              .equipmentCParams_refreshIcon {
                cursor: pointer;
                margin-left: 10px;
                font-size: 20px;
                color: #409EFF;
              }
            }
            .equipmentC_paramItem {
              width: 50%;
              height: 60px;
              display: flex;
              float: left;
              align-items: center;
              .equipmentC_paramName {
                width: 140px;
                color: #666;
                font-size: 16px;
              }
              .equipmentC_paramInput {
                width: 150px;
                .el-input{
                  width: 100%;
                }
              }
            }
          }
        }
      }
    }
    .equipmentC_echartsArea {
      width: 100%;
      height: 400px;
      float: left;
      margin-top: 10px;
      .equipmentC_echartsDndataBg {
        box-sizing: border-box;
        width: 50%;
        height: 100%;
        float: left;
        padding-right: 5px;
        .equipmentC_echartsDndata {
          width: 100%;
          height: 100%;
          background: white;
          border-radius: 6px;
        }
      }
      .equipmentC_echartsReflectivityBg {
        box-sizing: border-box;
        width: 50%;
        height: 100%;
        float: left;
        padding-left: 5px;
        .equipmentC_echartsReflectivity {
          width: 100%;
          height: 100%;
          background: white;
          border-radius: 6px;
        }
      }
    }
  }
  .dialogFooter {
    display: flex;
    justify-content: center;
    margin-top: 0.5rem;
  }
  .equipmentOCollectionParams_title {
    width: 100%;
    height: 28px;
    padding: 0 8px;
    box-sizing: border-box;
    background: linear-gradient(90deg,rgba(223,240,253,1), rgba(255,255,255,0));
    display: flex;
    align-items: center;
    .equipmentOCollectionParams_titleImg {
      width: 16px;
      height: 16px;
    }
    .equipmentOCollectionParams_titleText {
      line-height: 28px;
      font-size: 14px;
      color: #114ca6;
      margin-left: 6px;
    }
  }
  .calibrationInfo_table {
    width: 100%;
  }
  .echartForCalibrationBg {
    width: 100%;
    height: 720px;
    box-sizing: border-box;
    padding: 0px 20px;
    .echartForCalibration_bzb {
      width: 100%;
      height: 350px;
      float: left;
      margin-bottom: 20px;
      .echartForCalibration_bzbItem {
        width: 50%;
        float: left;
        height: 100%;
        box-sizing: border-box;
        padding: 0 10px;
        .echartForCalibrationItem_bzb {
          width: 100%;
          float: left;
          height: 100%;
        }
      }
    }
    .echartForCalibration_adl {
      width: 100%;
      height: 350px;
      float: left;
      .echartForCalibration_adlItem {
        width: 50%;
        float: left;
        height: 100%;
        padding: 0 10px;
        box-sizing: border-box;
        .echartForCalibrationItem_adl {
          width: 100%;
          float: left;
          height: 100%;
        }
      }
    }
  }
}
.equipmentC_lockBtnPop {
  margin-top: 4px!important;
}
</style>
